#include "connectionconfig.h"
#include "commandconfig.h"
#include "factoryconfig.h"
#include "utils.h"
#include "algorithm"

ConnectionConfig::ConnectionConfig(void)
{
}

ConnectionConfig::~ConnectionConfig(void)
{
	Utils::deleteData(brokers);
	Utils::deleteData(commands);
}

CommandConfig* const ConnectionConfig::getCommandConfig(const std::string& cmdName) const
{
	return Utils::findByName(commands, cmdName);
	/*for(std::vector<CommandConfig*>::const_iterator it = commands.begin(); it != commands.end(); it++)
	{
	if((*it)->name == cmdName)
	{
	return *it;
	}
	}
	return NULL;*/
}
FactoryConfig* const ConnectionConfig::getFactoryConfig(const std::string& factoryName) const
{
	return Utils::findByName(brokers, factoryName);
	//for(std::vector<FactoryConfig*>::const_iterator it = brokers.begin(); it != brokers.end(); it++)
	//{
	//	if((*it)->name == factoryName)
	//	{
	//		return *it;
	//	}
	//}
	//return NULL;
}

CommandConfig* ConnectionConfig::removeCommandConfig(const std::string& cmdName) 
{
	return Utils::removeByName(commands, cmdName);
}
FactoryConfig* ConnectionConfig::removeFactoryConfig(const std::string& factoryName)
{
	return Utils::removeByName(brokers, factoryName);
}